package com.dengyuanke.upms.controller;


import com.dengyuanke.upms.common.result.R;
import com.dengyuanke.upms.entity.Dept;
import com.dengyuanke.upms.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDateTime;

/**
 * <p>
 * 部门管理 前端控制器
 * </p>
 *
 * @author dengyuanke
 * @since 2019-06-29
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private IDeptService deptService;

    /**
     * 通过ID查询
     *
     * @param id ID
     * @return SysDept
     */
    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id) {
        return R.success(deptService.getById(id));
    }


    /**
     * 添加
     *
     * @param dept 实体
     * @return success/false
     */
    @PostMapping
    public R save(@Valid @RequestBody Dept dept) {
        return R.success(deptService.save(dept));
    }

    /**
     * 删除
     *
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Integer id) {
        return R.success(deptService.removeById(id));
    }

    /**
     * 编辑
     *
     * @param dept 实体
     * @return success/false
     */
    @PutMapping
    public R update(@Valid @RequestBody Dept dept) {
        return R.success(deptService.updateById(dept));
    }

}

